package monitor

import (
	"time"

	"gddgame.cc/galaxy/utils/orm"
)

var (
	ServerMonitorModel = orm.NewModel("server_monitor", &ServerMonitor{}, nil)
)

type RulePeriod byte

const (
	_ RulePeriod = iota
	Minute1Period
	Minute5Period
	Minute15Period
	Minute30Period
)

type RuleLogic int

const (
	_ RuleLogic = iota
	OnceLogic
	AlwaysLogic
	AvgLogic
)

type RuleRelation string

const (
	GeqRelation RuleRelation = ">="
	LeqRelation              = "<="
	EqRelation               = "="
	GqRelation               = ">"
	LqRelation               = "<"
)

type Rule struct {
	Metric   string       `json:"metric"`
	Period   RulePeriod   `json:"period"`
	Count    int          `json:"count"`
	Logic    RuleLogic    `json:"logic"`
	Relation RuleRelation `json:"relation"`
	Value    int32        `json:"value"`
}

type SilentPeriod = RulePeriod

type ServerMonitor struct {
	Id       int          `json:"id" orm:"auto" sql:"INT"`
	Server   string       `json:"server" sql:"VARCHAR"`
	Name     string       `json:"name" sql:"VARCHAR"`
	IsWhole  bool         `json:"is_whole" sql:"TINYINT"`
	Rules    []Rule       `json:"rules" sql:"JSON"`
	Publish  string       `json:"publish" sql:"VARCHAR"`
	Silent   SilentPeriod `json:"silent" sql:"TINYINT"`
	LastTime *time.Time   `json:"last_time" sql:"DATETIME"`
	Status   bool         `json:"status" sql:"TINYINT"`
}
